<?php

abstract class Kd_Data_Dcl_Expression_Base {

    private $_owner = NULL;
    private $_parentExpression = NULL;
    private $_childExpressions = NULL;

    protected function __construct() {
        $this->_childExpressions = new Kd_Collection_List();
    }

    public function getOwner() {
        return $this->_owner;
    }

    public function setOwner($value) {
        $this->_owner = $value;
        return $this;
    }

    public function getParentExpression() {
        return $this->_parentExpression;
    }

    public function setParentExpression($value) {
        $this->_parentExpression = $value;
        return $this;
    }

    public function getChildExpressions() {
        return $this->_childExpressions;
    }

    protected function addExpression(Kd_Data_Dcl_Expression_Base $expression) {
        $expression->setParentExpression($this)->setOwner($this->_owner);
        $this->_childExpressions->append($expression);
        return $this;
    }

    public function endSelf() {
        if (is_null($this->_parentExpression)) {
            return $this->getOwner();
        }
        return $this->getParentExpression();
    }

    public function closest() {
        return $this->_owner;
    }

    public function reset() {
        $this->getChildExpressions()->clear();
        return $this;
    }

    public abstract function getExpressionType();
}